package sjtu.pirate.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.commons.io.IOUtils;
/**
 * @author wilbur.ma@qq.com
 * @date 2011.06.01
 */
public class FileUtil {
	public static void copy(String src, String target) throws IOException {
		copy(new File(src), new File(target));
	}
	
	public static void copy(File src, File target) throws IOException {
		if (!target.getParentFile().exists())
			target.getParentFile().mkdirs();
		try {
			IOUtils.copy(new FileInputStream(src), new FileOutputStream(target));
			System.out.println("File copied: " + target.getAbsolutePath());
		} catch (FileNotFoundException e) {
			System.err.println("File copy error: " + e.getMessage());
		}
	}
}
